home *** CD-ROM | disk | FTP | other *** search
- Path: sierra.net!usenet
- From: "Tyler G. Colwell" <snowbull@sierra.net>
- Newsgroups: comp.lang.c++
- Subject: Re: Dumb Question? about ptr
- Date: Thu, 11 Jan 1996 08:40:41 -0800
- Organization: Sierra-Net
- Message-ID: <30F53D89.3473@sierra.net>
- References: <00001a81+00008b8f@msn.com>
- NNTP-Posting-Host: 204.94.232.59
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b5 (WinNT; I)
-
- You can return the address of a class, only of an object that
- has been declared a member of that class. Also, my compiler
- (VC++) would only compile this if I placed the declarations
- inside main(). Can anyone tell us why this is necessary?
-
- In other words, try this:
-
- #include <iostream.h>
-
- class MyStruct {
- public:
- int data;
- int value;
- };
-
-
- void main() {
- MyStruct *foo;
- MyStruct Record1;
- foo = &Record1; // <-----Note change here
- foo->data=5;
- cout << foo->data;
- };
-